package org.dant.ant.extension.net.rmi;
	
import java.net.*;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import org.dant.ant.extension.tasks.internal.Endpoint;

public class DistributedAntServer {

  public static void main(String args[]) throws Exception {

    try {
      DistributedAntImpl obj = new DistributedAntImpl();
      
      Endpoint ep = new Endpoint();
      String port = ep.getPort();
      if (args.length == 1) {
          port = args[0];
      }
      
      if (ep.getIp() != null && !"127.0.0.1".equals(ep.getIp())) {
          String endpoint_ip = ep.constructEndPoint(ep.getIp(), port);
          obj.setFullURL(endpoint_ip);
          Naming.rebind(endpoint_ip, obj);
          System.out.println("Running on port " + endpoint_ip);
      } else if (ep.getHostname() != null && !"localhost".equals(ep.getHostname())) {
          String endpoint_hostname = ep.constructEndPoint(ep.getHostname(), port);
          obj.setFullURL(endpoint_hostname);
          Naming.rebind(endpoint_hostname, obj);
          System.out.println("Running on port " + endpoint_hostname);
      }

      
    } catch (Exception e) {
      System.out.println("HelloImpl err: " + e.getMessage());
      e.printStackTrace();
    }
  }
}

